package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.Permission;
import cn.wolfcode.crm.qo.JsonResult;
import cn.wolfcode.crm.service.IPermissionService;
import cn.wolfcode.crm.qo.QueryObject;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {
    @Autowired
    private IPermissionService permissionService;

    @RequestMapping("/list")
    public String list(QueryObject queryObject, Model model){
        PageInfo<Permission> pageResult = permissionService.selectByQuery(queryObject);
        //List<Permission> list = permissionService.getAll();
        model.addAttribute("result",pageResult);
        return "permission/list";
    }
    @RequestMapping("/delete")
    @ResponseBody
    public JsonResult delete(Long id){
        try {
            permissionService.delete(id);
            return new JsonResult();
        } catch (Exception e) {
            e.printStackTrace();
            return new JsonResult(false,"删除失败");
        }
    }
    @RequestMapping("/reload")
    public String reload(){
        permissionService.selectAllExpressions();
        return "redirect:/permission/list.do";
    }



}
